#!/usr/bin/env python2.5
"""

  get_parameter_path module

       get_module_path 
       parameter_path   contains the path to parameter files
       project_path


   Copyright (C) 2007 Leo Goodstadt

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License
   as published by the Free Software Foundation; version 2
   of the License

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
"""


import sys, os, re


def get_module_path (module_name):
    '''
    Get the path of this module

        If this is main, just read of arguments
        else go through search path and find self
    '''
    if module_name == "__main__":
        return os.path.split(os.path.abspath(sys.argv[0]))[0]
    else:
    
        #   
        #   for each path in search path, check if module is there
        # 
        for path in sys.path :
            path = os.path.abspath(path)
            if sys.platform == 'win32':
                path=path.lower()
            if (os.path.isfile(os.path.join(path, module_name+".py"))):
                return path
        else:
            raise NameError, ("Module %s not found on search path!!\n"  
                                    % module_name) + ";".join(sys.path)

parameter_path = os.path.abspath(
                    os.path.join(get_module_path(__name__), "..", "parameters"))

project_path = os.path.abspath(
                    os.path.join(get_module_path(__name__), "..")
                    )

#
#   unit test
#

if __name__ == '__main__':
    print "%-20s path = %s" % ("This module's", get_module_path('get_parameter_path'))
    print "%-20s path = %s" % ("__main__'s ", get_module_path('__main__'))
    print "%-20s path = %s" % ("parameter ", parameter_path)

